package cn.lj.base.service.impl;

import cn.lj.base.Mapper.BaseMapper;
import cn.lj.base.query.BaseQuery;
import cn.lj.base.service.IBaseService;
import cn.lj.base.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T>{

    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @Transactional
    public void add(T t) {
        baseMapper.save(t);
    }
    @Override
    @Transactional
    public void upadte(T t) {
        baseMapper.update(t);
    }
    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.remove(id);
    }
    @Override
    @Transactional
    public void patchdel(List<Long> ids) {
        baseMapper.patchdel(ids);
    }
    @Override
    public T getById(Long id) {
        T t = baseMapper.loadById(id);
        return t;
    }
    @Override
    public List<T> getAll() {
        List<T> tList = baseMapper.loadAll();
        return tList;
    }
    @Override
    public PageList<T> queryData(BaseQuery query) {
        Long count = baseMapper.queryCount(query);
        List<T> list = baseMapper.queryData(query);
        return new PageList<T>(count,list);
    }
}
